package com.feilong.cn.mybatis.autoV2.plugin;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by yangxulong on 2018/4/9.
 */
public class AutoInterceptorChain {
    private List<AutoInterceptor> lstInterceptors = new ArrayList<>();

    public Object PluginAll(Object target) {
        for (AutoInterceptor interceptor : lstInterceptors) {
            //使用plugin对target(handler/executor)代理包装, 此处为多次代理
            target = interceptor.plugin(target);
        }
        return target;
    }

    public void addInterceptor(AutoInterceptor inc) {
        this.lstInterceptors.add(inc);
    }

    public List<AutoInterceptor> getInterceptors() {
        return Collections.unmodifiableList(lstInterceptors);
    }

}
